package team.scau.laboratory_repair.common.activiti.dto;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.runtime.ProcessInstance;
import team.scau.laboratory_repair.common.utils.DateTool;

import java.util.*;

/**
 * @author 30254
 * creadtedate:2018/10/22
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class RepairProcDto {
    private String id;
    private String key;
    private String name;
    private String startTime;
    private String endTime;
    private String taskName;
    private String assignee;
    private String area;
    private String room;
    private LinkedList<RepairTaskDto> list = new LinkedList<>();
    private Map<String, Object> vars;

    public RepairProcDto(HistoricProcessInstance h, List<RepairTaskDto> hl, Map<String, Object> data){
        id = h.getId();
        key = h.getProcessDefinitionKey();
        name = h.getProcessDefinitionName();
        startTime = DateTool.formatDate(h.getStartTime());
        endTime = DateTool.formatDate(h.getEndTime());
        RepairTaskDto last = hl.get(0);
        taskName = last.getTaskName();
        assignee = last.getAssignee();
        list.addAll(hl);
        vars = data;
    }

    public RepairProcDto(ProcessInstance p, List<RepairTaskDto> hl, Map<String, Object> data){
        id = p.getProcessInstanceId();
        key = p.getProcessDefinitionKey();
        name = p.getProcessDefinitionName();
        startTime = DateTool.formatDate(p.getStartTime());
        RepairTaskDto last = hl.get(hl.size()-1);
        taskName = last.getTaskName();
        assignee = last.getAssignee();
        list.addAll(hl);
        vars = data;
    }
}
